// 案件管理  case
import layer from '@/components/layer'
import permission from '@/components/permission'
import dicts from '@/mixins/dicts'
import filters from '@/mixins/filters'
import { TreeToArray } from '@/utils'
import { formatDate } from '@/mixins/filters'
export default {
	mixins: [dicts],
	data() {
		return {
			filter: filters.filters,
			changeType: '',
			viewContentLayer: {
				show: false,
				title: '',
				content: '',
				btns: ['关闭']
			},
			tableData: {
				filter: {
					pageBean: {
						pageIndex: 1,
						pageSize: 10
					}
				},
				sizes: 10,
				data: [],
				rules: {
					reflectPhone: { pattern: /^1[3|5|6|7|8|9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' },
					beReportedPhone: { pattern: /^1[3|5|6|7|8|9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
				}
			}
		}
	},
	computed: {
		deptList() {
			return TreeToArray({ tree: this.$store.state.system.deptList })
		}
	},
	components: {
		layer,
		permission
	},
	mounted() {
		if (this.$store.state.system.deptList && this.$store.state.system.deptList.length == 0) {
			this.$store.dispatch('getDeptList')
		}
	},
	methods: {
		// 筛选   
		sumbitSave() {
			if (this.riskCategoryForm.id) {
				let _category = this.dicts.riskCategory.find(item => item.id == this.riskCategoryForm.id)
				if (_category) {
					this.tableData.filter.riskCategory = _category.value
				}
			}
			else {
				this.tableData.filter.riskCategory = ''
			}
			if (this.riskTypeForm.value) {
				this.tableData.filter.riskType = this.riskTypeForm.value
			}
			else {
				this.tableData.filter.riskType = ''
			}
			if (this.riskLevelForm.value) {
				this.tableData.filter.riskLevel = this.riskLevelForm.value
			}
			else {
				this.tableData.filter.riskLevel = ''
			}
			api.queryCase(this.tableData.filter).then(res => {
				this.tableData.total = res.totalCount
				res.list.map(item => {
					if (item.gainCaseDate) {
						item.gainCaseDate = formatDate(item.gainCaseDate)
					}
					if (item.registerDate) {
						item.registerDate = formatDate(item.registerDate)
					}
					if (item.gainCaseDate) {
						item.gainCaseDate = formatDate(item.gainCaseDate)
					}
					if (item.threadDate) {
						item.threadDate = formatDate(item.threadDate)
					}
					if (item.cdate) {
						item.cdate = formatDate(item.cdate)
					}
					if (item.source) {
						let _obj = this.dicts.sourceType.find(o => o.value == item.source)
						if (_obj) {
							item.sourceName = _obj.name
						}
					}
					if (item.product) {
						let _obj = this.dicts.productType.find(o => o.value == item.product)
						if (_obj) {
							item.productName = _obj.name
						}
					}
					if (item.riskType) {
						let _obj = this.dicts.riskType.find(o => o.value == item.riskType)
						if (_obj) {
							item.riskTypeName = _obj.name
						}
					}
					if (item.riskCategory) {
						let _obj = this.dicts.riskCategory.find(o => o.value == item.riskCategory)
						if (_obj) {
							item.riskCategoryName = _obj.name
						}
					}
					if (item.riskLevel) {
						let _obj = this.dicts.riskLevel.find(o => o.value == item.riskLevel)
						if (_obj) {
							item.riskLevelName = _obj.name
						}
					}
					if (item.caseType) {
						let _obj = this.dicts.caseType.find(o => o.value == item.caseType)
						if (_obj) {
							item.caseTypeName = _obj.name
						}
					}
					return item
				})
				this.tableData.data = res.list
			}, error => { })

		},
		// 重置筛选条件
		reset() {
			this.initRiskData()
			this.tableData.filter = { pageBean: { pageIndex: 0, pageSize: 10 } }
			this.sumbitSave()
		},
		// 分页改变
		sizeChange(val) {
			this.tableData.filter.pageBean.pageIndex = 1;
			this.tableData.filter.pageBean.pageSize = val;
			this.sumbitSave()
		},
		// 当前页面改变
		currentChange(val) {
			this.tableData.filter.pageBean.pageIndex = val;
			this.sumbitSave()
		}
	}
}